var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
Page({
  data: {
    imgUrl: globalData.imgUrl,
    businessCode:'',
  },
  onLoad: function (options) {
    console.log("options:" + JSON.stringify(options));
    if (options.businessCode != undefined && options.businessCode != null && options.businessCode != '') {
      // this.setData({ businessCode: options.businessCode})
      let businessCode = options.businessCode;
      let codeUrl = httpsUrl + "/wechat/getXcxCodeByPoster?scene=0," + businessCode + "&agentCode=" + globalData.agentCode;
      console.log(codeUrl);
      this.setData({ codeUrl: codeUrl})
      this.imgs();
    }
  },
  imgs:function(){
    let that = this;
    let ctx = wx.createCanvasContext('testCanvas');
    //真机展示的坑：1.网络图片必须得先下载 2.图片域名必须加到downloadFile合法域名里
    wx.showLoading({ title: '加载中...', })
    wx.getImageInfo({
      src: that.data.imgUrl + '/shop-code-bg.png',
      success: function (res) {
        wx.hideLoading();
        let Path = res.path;//res.path是网络图片的本地地址
        ctx.drawImage(Path, 0, 0, 300, 400);
        wx.getImageInfo({
          src: that.data.codeUrl,
          success: function (res3) {
            let Path3 = res3.path;
            ctx.drawImage(Path3, 73, 200, 155, 150);
            ctx.draw();
          },
        })
      },
      fail: function (res) {
        wx.hideLoading();
        wx.showModal({ title: '提示', content: '图片下载失败，请刷新重试！', })
      }
    })
  },
  clickMe: function () {
    wx.canvasToTempFilePath({
      canvasId: 'testCanvas',
      fileType: 'jpg',
      success: function (res) {
        wx.saveImageToPhotosAlbum({
          filePath: res.tempFilePath,
          success(res) {
            console.log(res)
            wx.showToast({ title: '保存成功！' });
          },
          fail() { }
        })
      }
    })
  },
})